package com.njh.check.controller.apis;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.hos.entity.his.CareOrderItem;
import com.hos.entity.his.CheckResult;
import com.hos.vo.Result;
import com.njh.check.service.CheckService;
import com.njh.check.service.FileService;
import com.njh.check.vo.CheckQueryParamsVo;
import com.njh.check.vo.CheckingResultImgVo;
import com.njh.check.vo.CheckingVo;
import com.njh.check.vo.NewCheckReturnVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @author ：njh
 * @date ：Created in 2023/12/15 16:43
 * @description：
 * @modified By：
 * @version:
 */
@RestController
@RequestMapping("/check/api/check")
@Api(tags = "检查管理相关接口")
public class ApiCheckController {

    @Resource
    private CheckService checkService;
    @Resource
    private FileService fileService;

    @PostMapping("queryAllCheckResultForPage")
    @ApiOperation("查询所有检查的项目")
    public Result queryAllCheckResultForPage(@RequestBody CheckQueryParamsVo queryParams) {

        Page<CheckResult> checkResultPage = checkService.queryAllCheckResultForPage(queryParams);
        Result result=new Result(200,"查询成功",checkResultPage);

        return result;
    }

    @PostMapping("queryNeedCheckItem")
    @ApiOperation("根据挂号单号和项目IDS查询要检查的项目")
    public Result queryNeedCheckItem(@RequestBody CheckQueryParamsVo queryParams) {

        List<CareOrderItem> careOrderItems = checkService.queryNeedCheckItem(queryParams);
        Result result=new Result(200,"查询成功",careOrderItems);
        return  result;

    }

    @GetMapping("queryCheckItemByItemId/{itemId}")
    @ApiOperation("根据检查单号查询要检查的项目详情")
    public Result queryCheckItemByItemId(@PathVariable String itemId) {

        NewCheckReturnVo newCheckReturnVo = checkService.queryCheckItemByItemId(itemId);
        Result result=new Result(200,"查询成功",newCheckReturnVo);
        return  result;

    }

    @PostMapping("startCheck/{itemId}")
    @ApiOperation("根据检查单号查询要检查的项目详情")
    public Result startCheck(@PathVariable String itemId) {

        Integer integer = checkService.startCheck(itemId);
        Result result=new Result(200,"开始检查成功",integer);
        return  result;

    }

    @PostMapping("queryAllCheckingResultForPage")
    @ApiOperation("查询所有检查中的项目")
    public Result queryAllCheckingResultForPage(@RequestBody CheckQueryParamsVo queryParams) {

        Page<CheckResult> checkResultPage = checkService.queryAllCheckingResultForPage(queryParams);
        Result result=new Result(200,"查询成功",checkResultPage);
        return  result;

    }

    @PostMapping("completeCheckResult")
    @ApiOperation("完成检查")
    public Result completeCheckResult(@RequestBody CheckingVo checkingVo) throws JsonProcessingException {

        System.out.println(checkingVo);
        Integer integer = checkService.completeCheckResult(checkingVo);
        Result result=new Result(200,"查询成功",integer);
        return  result;

    }

//    @PostMapping("doUploadImage")
//    @ApiOperation("完成检查")
//    public Result doUploadImage(MultipartFile file) {
//
//        fileServiceTest f=new fileServiceTest();
//        Map<String,Object> map = f.addFile(file);
//        return new Result(200,"图片上传成功",map);
//
//    }

    @PostMapping("imgup")
    @ResponseBody
    @ApiOperation("图片上传")
    public Result imgUp(@RequestParam("file") MultipartFile file) throws IOException {

        CheckingResultImgVo result = fileService.upload(file);
        return new Result(200,"图片上传成功",result);
    }


    @GetMapping("/imgdelete")
    @ResponseBody
    @ApiOperation("上传图片的删除")
    public Result imgDelete(@RequestParam("url") String url) {
        fileService.removeFile(url);
        return new Result(200,"图片删除成功",null);
    }



}